

#import "FAMMineTableFooterView.h"
@interface FAMMineTableFooterView()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *FAMPolicyTextView;

@end
@implementation FAMMineTableFooterView

- (instancetype)initWithFrame:(CGRect)frame{
    self  = [super initWithFrame:frame];
    if (self) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FAMMineTableFooterView" owner:self options:nil];
        self = array.firstObject;
        self.FAMPolicyTextView.delegate = self;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithAttributedString:self.FAMPolicyTextView.attributedText];
        [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, attributedString.length)];
        [attributedString addAttribute:NSLinkAttributeName
                                     value:@"healthline://"
                                     range:[[attributedString string] rangeOfString:@"· Basal metabolic rate"]];
        [attributedString addAttribute:NSLinkAttributeName
                                 value:@"health://"
                                 range:[[attributedString string] rangeOfString:@". Calorie counting-Harvard"]];
        [attributedString addAttribute:NSLinkAttributeName
                                 value:@"pubmed://"
                                 range:[[attributedString string] rangeOfString:@". International Society of Sports Nutrition"]];
        [attributedString addAttribute:NSLinkAttributeName
                                 value:@"nhlbi://"
                                 range:[[attributedString string] rangeOfString:@". National Institutes of Health"]];
        self.FAMPolicyTextView.attributedText = attributedString;
        self.FAMPolicyTextView.editable = NO;
        self.FAMPolicyTextView.scrollEnabled = NO;
    }
    return self;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    if ([[URL scheme] isEqualToString:@"healthline"]) {
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://www.healthline.com/health/what-is-basal-metabolic-rate"] options:@{} completionHandler:nil];
        return NO;
    } else if ([[URL scheme] isEqualToString:@"health"]) {
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://www.health.harvard.edu/staying-healthy/calorie-counting-made-easy"] options:@{} completionHandler:nil];
        return NO;
    }else if ([[URL scheme] isEqualToString:@"pubmed"]) {
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://pubmed.ncbi.nlm.nih.gov/28630601/"] options:@{} completionHandler:nil];
        return NO;
    }else if ([[URL scheme] isEqualToString:@"nhlbi"]) {
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"https://www.nhlbi.nih.gov/files/docs/guidelines/ob_gdlns.pdf"] options:@{} completionHandler:nil];
        return NO;
    }
    return YES;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 350);
}
@end
